package com.audible.library.domain.beans;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * This is a lightweight persistence domain object representing audio_book table in the database.
 *
 * @author Jigar Shah
 * @version 0.1
 */
@Entity
@Table(name = "audio_book")
@NamedQueries({
    @NamedQuery(name = "AudioBook.findAll", query = "SELECT a FROM AudioBook a"),
    @NamedQuery(name = "AudioBook.findById", query = "SELECT a FROM AudioBook a WHERE a.id = :id"),
    @NamedQuery(name = "AudioBook.findByTitle", query = "SELECT a FROM AudioBook a WHERE a.title = :title"),
    @NamedQuery(name = "AudioBook.findByAuthor", query = "SELECT a FROM AudioBook a WHERE a.author = :author"),
    @NamedQuery(name = "AudioBook.findByLengthInSec", query = "SELECT a FROM AudioBook a WHERE a.lengthInSec = :lengthInSec"),
    @NamedQuery(name = "AudioBook.findByFormat", query = "SELECT a FROM AudioBook a WHERE a.format = :format")})
public class AudioBook implements Serializable {

    private static final long serialVersionUID = -5267987910855591472L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID")
    private Integer id;

    @Basic(optional = false)
    @Column(name = "TITLE")
    private String title;

    @Basic(optional = false)
    @Column(name = "AUTHOR")
    private String author;

    @Basic(optional = false)
    @Column(name = "LENGTH_IN_SEC")
    private int lengthInSec;

    @Basic(optional = false)
    @Column(name = "FORMAT")
    private String format;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "audioBook")
    private Collection<UserAudioBook> userAudioBookCollection;

    public AudioBook() {
    }

    public AudioBook(Integer id) {
        this.id = id;
    }

    public AudioBook(Integer id, String title, String author, int lengthInSec, String format) {
        this.id = id;
        this.title = title;
        this.author = author;
        this.lengthInSec = lengthInSec;
        this.format = format;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public int getLengthInSec() {
        return lengthInSec;
    }

    public void setLengthInSec(int lengthInSec) {
        this.lengthInSec = lengthInSec;
    }

    public String getFormat() {
        return format;
    }

    public void setFormat(String format) {
        this.format = format;
    }

    public Collection<UserAudioBook> getUserAudioBookCollection() {
        return userAudioBookCollection;
    }

    public void setUserAudioBookCollection(Collection<UserAudioBook> userAudioBookCollection) {
        this.userAudioBookCollection = userAudioBookCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof AudioBook)) {
            return false;
        }
        AudioBook other = (AudioBook) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.audible.library.domain.beans.AudioBook[id=" + id + "]";
    }

}
